package com.geekmvc;

import com.geekmvc.feign.CoffeeFeign;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.Banner;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
//import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

@SpringBootApplication
@Slf4j
@EnableFeignClients(basePackages = "com.geekmvc.feign")
public class ReqMvcApp  implements ApplicationRunner {

    @Resource
    private CoffeeFeign coffeeFeign;

    public static void main(String[] args) {
        new SpringApplicationBuilder()
                .sources(ReqMvcApp.class)
                .bannerMode(Banner.Mode.OFF)
                .web(WebApplicationType.NONE)
                .run(args);
    }

    @Override
    public void run(ApplicationArguments args) throws Exception {
        restReq();
        feignReq();
    }

    private void restReq(){
        RestTemplate restTemplate = new RestTemplate();
        String result = restTemplate.getForEntity("http://localhost:8080/coffee/json/",
                String.class).getBody();
        log.info("resttemplate结果:{}"+result);
    }
    private void feignReq(){
        String coffeeAll = coffeeFeign.getCoffeeAll();
        log.info("feign结果:{}"+coffeeAll);
    }
}
